<?php

namespace App\Http\Controllers;

use App\like;
use backend\widgets\RangeWidget;
use Illuminate\Http\Request;

class LikeController extends Controller
{
    public function add(Request  $request){
        $params = $request->input();
       $falg =  like::where($params)->exists();
       if ($falg){
           return ['code'=>300,'msg'=>'该用户已经给这篇文章点过赞','data'=>''];
       }else{
           $like = new like();
           $like->uid = $params['uid'];
           $like->aid = $params['aid'];
          $res =  $like->save();
          if ($res){
              return ['code'=>200,'msg'=>'点赞成功','data'=>''];
          }else{
              return ['code'=>300,'msg'=>'点赞失败','data'=>''];
          }
       }
    }

    public function getCount(Request  $request){
        $params = $request->input();
        $count = like::where('aid',$params['aid'])->count();
        return $count;
    }
}
